window.onload=function(){
    let btn=document.querySelector("button")
    let btn_post=document.querySelector("#btn_post")

    btn.addEventListener("click",(e)=>{
        e.preventDefault()

        let username=document.getElementById("username").value
        let password=document.getElementById("password").value

        fetch("http://172.19.1.251:8080/login",{
            method:"GET",
            headers:{
                "Content-Type":"application/x-www-form-url-encoded"
            }
        }).then((res)=>{
            console.log("请求成功")
            // res.json()
            return res.text()
        }).then((res)=>{
            console.log(res)
            return new Promise((resolve,reject)=>{
                resolve("想下课.then()")
            })
        }).then((res)=>{
            console.log(res)
        }).catch(()=>{
            console.log("请求失败")
        })
    })

    btn_post.addEventListener("click",(e)=>{
        e.preventDefault()

        let username=document.getElementById("username").value
        let password=document.getElementById("password").value
        let data={
            username:username,
            password:password
        }
        let dataJson=JSON.stringify(data)
        console.log(dataJson)

        fetch("http://172.19.1.251:8080/login",{
            method:"POST",
            headers:{
                "Content-Type":"application/json"
            },
            body:dataJson
        }).then(()=>{
            console.log("成功")
        }).catch(()=>{
            console.log("失败")
        })
    })
}